package myapp.com.xm.myapplication.Utils;

import android.text.TextUtils;
import android.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class FUCK {
    public static final String key = "aaaaaaaa";
    public static final int len = 25;
    public static final String completion = "//////////0000000000//////////";

    public static String desEncrypt(String str) throws Exception {
        if (TextUtils.isEmpty(str)) return null;
        Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "DES"));
        byte[] bytes = cipher.doFinal(str.getBytes("utf-8"));
        return Base64.encodeToString(bytes, Base64.NO_WRAP).length() > len ? Base64.encodeToString(bytes, Base64.NO_WRAP) : Base64.encodeToString(bytes, Base64.NO_WRAP) + completion;
    }


    public static String desDecrypt(String str) throws Exception {
        if (TextUtils.isEmpty(str)) return null;
        if (str.contains(completion)) str = str.replace(completion, "");
        byte[] bytes = Base64.decode(str, Base64.NO_WRAP);
        Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "DES"));
        bytes = cipher.doFinal(bytes);
        return new String(bytes, "utf-8");
    }


}
